window.addEventListener('load', function () {
    let al = this.document.querySelectorAll('.news-al');
    let ar = this.document.querySelectorAll('.news-ar');
    let loopul = this.document.querySelectorAll('.news-main_text_loop');
    let loopli = this.document.querySelectorAll('.news-text-li_1');
    let lilength = loopli[0].offsetHeight;

    /* 获取轮播图片部分的元素 */
    let imgloopul = this.document.querySelectorAll('.news-main_img');
    let imgloopli = this.document.querySelectorAll('.news-main_img_li');
    let imgloopli2=this.document.querySelectorAll('.news-main_imgli_2');
    let imgloopli3=this.document.querySelectorAll('.news-main_imgli_3');
    let imgloopli4=this.document.querySelectorAll('.news-main_imgli_4');
    let imgloopli5=this.document.querySelectorAll('.news-main_imgli_5');
    let imglilength = imgloopli[0].offsetWidth;
    /* 声明一个索引 */
    let index = 0;

    /* 右边的箭头对应的照片 */
    function animateimgar(obj, target) {
        clearInterval(obj.timer);  /*防抖节流 */
        obj.timer = setInterval(function () {
            var step = ((target - obj.offsetLeft) / 10);
            step = step > 0 ? Math.ceil(step) : Math.floor(step);
            if (obj.style.left == target) {
                clearInterval(obj.timer);
            }
            obj.style.left = obj.offsetLeft + step + 'px';
        }, 20)
    }
    /*animateimgar(); */

    /* 右边箭头对应的文字 */
    function animatetextar(obj, target) {
        clearInterval(obj.texttimer);
        obj.texttimer = setInterval(function () {

            var step = ((target - obj.offsetTop) / 10);
            step = step > 0 ? Math.ceil(step) : Math.floor(step);

            if (obj.style.top == target) {
                clearInterval(obj.texttimer);
            }
            obj.style.top = obj.offsetTop + step + 'px';
        }, 30)
    }
    /*animatetextar();*/

    /* 左边的箭头对应的照片 */
    function animateimgal(obj, target) {
        clearInterval(obj.timer); /* 防抖节流 */

        obj.timer = setInterval(function () {

            var step = ((target - obj.offsetLeft) / 10);
            step = step > 0 ? Math.ceil(step) : Math.floor(step);

            if (obj.style.left == target) {
                clearInterval(obj.timer);
            }
            obj.style.left = obj.offsetLeft + step + 'px';
        }, 20)
    }
    /*animateimgal();*/

    /* 左箭头的文字 */
    function animatetextal(obj, target) {
        clearInterval(obj.texttimer);
        obj.texttimer = setInterval(function () {

            var step = ((target - obj.offsetTop) / 10);
            step = step > 0 ? Math.ceil(step) : Math.floor(step);

            if (obj.style.top == target) {
                clearInterval(obj.texttimer);
            }
            obj.style.top = obj.offsetTop + step + 'px';
        }, 30)
    }
    /* animatetextal(); */

   /* 第一部分 */
   /* 右边箭头 */
    ar[0].addEventListener('click', function () {
        index++;

        if (index >= imgloopli.length) {
            index = 0;
        }
        console.log(index)
        animateimgar(imgloopul[0], -index * imglilength);
        animatetextar(loopul[0], -index * lilength);
    })
    
    /* 左边箭头 */ 
    al[0].addEventListener('click', function () {

        index--;

        if (index < 0) {
            index = imgloopli.length - 1
        }
        console.log(index)
        animateimgar(imgloopul[0], -index * imglilength);
        animatetextar(loopul[0], -index * lilength);
    })

/* 第二部分 */
   /* 右边箭头 */
   let index2=0;
   ar[1].addEventListener('click', function () {
    index2++;

    if (index2 >= imgloopli2.length) {
        index2 = 0;
    }
    console.log(index2)
    animateimgar(imgloopul[1], -index2 * imglilength);
    animatetextar(loopul[1], -index2 * lilength);
})

/* 左边箭头 */
al[1].addEventListener('click', function () {

    index2--;

    if (index2 < 0) {
        index2 = imgloopli2.length - 1
    }
    animateimgal(imgloopul[1], -index2 * imglilength);
    animatetextal(loopul[1], -index2 * lilength);
})


/* 第三部分 */
   /* 右边箭头 */
   let index3=0;
   ar[2].addEventListener('click', function () {
    index3++;

    if (index3 >= imgloopli3.length) {
        index3 = 0;
    }
    animateimgar(imgloopul[2], -index3 * imglilength);
    animatetextar(loopul[2], -index3 * lilength);
})

/* 左边箭头 */
al[2].addEventListener('click', function () {

    index3--;

    if (index3 < 0) {
        index3 = imgloopli3.length - 1
    }
    console.log(index)
    animateimgal(imgloopul[2], -index3 * imglilength);
    animatetextal(loopul[2], -index3 * lilength);
})


/* 第四部分 */
   /* 右边箭头 */
   let index4=0;
   ar[3].addEventListener('click', function () {
    index4++;

    if (index4 >= imgloopli4.length) {
        index4 = 0;
    }
    animateimgar(imgloopul[3], -index4 * imglilength);
    animatetextar(loopul[3], -index4 * lilength);
})

/* 左边箭头 */
al[3].addEventListener('click', function () {

    index4--;

    if (index4 < 0) {
        index4 = imgloopli4.length - 1
    }
    animateimgal(imgloopul[3], -index4 * imglilength);
    animatetextal(loopul[3], -index4 * lilength);
})


/* 第五部分 */
   /* 右边箭头 */
   let index5=0;
   ar[4].addEventListener('click', function () {
    index5++;

    if (index5 >= imgloopli5.length) {
        index5 = 0;
    }
    console.log(loopul[4])
    animateimgar(imgloopul[4], -index5 * imglilength);
    animatetextar(loopul[4], -index5 * lilength);
})

/* 左边箭头 */

al[4].addEventListener('click', function () {

    index5--;

    if (index5 < 0) {
        index5 = imgloopli5.length - 1
    }
    animateimgal(imgloopul[4], -index5 * imglilength);
    animatetextal(loopul[4], -index5 * lilength);
})
console.log(loopul.length)
})

